import java.io.BufferedReader;

public class Anagram {
	private static int specificCharAmount(String string, char character) {
		int amount = 0;
		
		for (int index = 0; index < string.length(); ++index) {
			if (string.charAt(index) == character) {
				++amount;
			}
		}
		
		return amount;
	}
	
	private static String removeWhitespaces(String string) {
		String whitespace = "";
		String stringWithoutWhitespaces = string;
		
		for (int index = 0; index < string.length(); ++index) {
			if (Character.isWhitespace(string.charAt(index))) {
				whitespace = "" + string.charAt(index);
				stringWithoutWhitespaces = stringWithoutWhitespaces.replaceAll(whitespace, "");
			}
		}
		
		return stringWithoutWhitespaces;
	}

	public static boolean isAnagram(String string1, String string2) {
		String string1WithoutWhitespaces = removeWhitespaces(string1).toLowerCase();
		String string2WithoutWhitespaces = removeWhitespaces(string2).toLowerCase();
		
		if (string1WithoutWhitespaces.length() != string2WithoutWhitespaces.length()) {
			return false;
		} else {
			for (int index = 0; index < string1WithoutWhitespaces.length(); ++index) {
				if (specificCharAmount(string1WithoutWhitespaces, string1WithoutWhitespaces.charAt(index)) != 
					specificCharAmount(string2WithoutWhitespaces, string1WithoutWhitespaces.charAt(index))) {
					return false;
				}
			}
		}
		
		return true;
	}
	
	public static void main(String[] args) {
		BufferedReader consoleReader = new BufferedReader(new java.io.InputStreamReader(System.in));
		String string1, string2;
		
		System.out.println("Anagram tester");
		
		try {
			System.out.print("Enter first string: ");
			string1 = consoleReader.readLine();
			System.out.print("Enter second string: ");
			string2 = consoleReader.readLine();
		} catch (java.io.IOException ex) {
			System.out.println("Caught IO error!");
			System.out.println(ex);
			return;
		}
		
		if (isAnagram(string1, string2)) {
			System.out.println("\"" + string1 + "\" and \"" + string2 + "\" are anagrams.");
		} else {
			System.out.println("\"" + string1 + "\" and \"" + string2 + "\" aren't anagrams.");
		}
	}
}